//package com.plian.system.controller.hr.staff;
//
//import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
//import com.baomidou.mybatisplus.core.metadata.IPage;
//import com.baomidou.mybatisplus.core.toolkit.Wrappers;
//import com.plian.Tools.*;
//import com.plian.Tools.base.BaseController;
//import com.plian.Tools.pagedata.PageData;
//import com.plian.system.config.Resubmit;
//import com.plian.system.constant.sys.FormTypeConstant;
//import com.plian.system.dto.hr.staff.DirectorDTO;
//import com.plian.system.entity.hr.staff.Director;
//import com.plian.system.model.CommonCode;
//import com.plian.system.model.ListResult;
//import com.plian.system.model.ObjResult;
//import com.plian.system.model.R;
//import com.plian.system.mybatis.search.SearchEntity;
//import com.plian.system.mybatis.search.SearchParamEntiy;
//import com.plian.system.mybatis.support.Condition;
//import com.plian.system.mybatis.support.Query;
//import com.plian.system.service.hr.staff.IDirectorService;
//import com.plian.system.vo.hr.staff.DirectorVO;
//import com.plian.system.vo.report.ReportReturnVO;
//import com.plian.system.wrapper.hr.staff.DirectorWrapper;
//import lombok.AllArgsConstructor;
//import lombok.extern.slf4j.Slf4j;
//import org.apache.commons.lang3.StringUtils;
//import org.springframework.web.bind.annotation.*;
//
//import javax.validation.Valid;
//import java.util.List;
//import java.util.Optional;
//
//import static com.plian.system.constant.sys.BaseConstant.BASE64_KEY;
//
///**
// * @description:董事会
// * @author: gangan
// * @create: 2020-03-15 19:51
// */
//@Slf4j
//@RestController
//@AllArgsConstructor
//@RequestMapping("api/director")
//public class DirectorController  extends BaseController {
//
//    private IDirectorService directorService;
//
//    private DirectorWrapper directorWrapper;
//
//    /**
//     * 详情
//     */
//    @PostMapping("/detail")
//    public R<DirectorVO> detail(@Valid @RequestBody Director director) {
//        Director detail = directorService.getOne(Condition.getQueryWrapper(director));
//        DirectorVO directorVO = directorWrapper.entityToVO(detail);
//        return R.data(directorVO);
//    }
//
//    /**
//     * 分页 董事会
//     */
//    @PostMapping("/list")
//    public ListResult<DirectorVO> list(@Valid @RequestBody Query query) {
//        if(query.getAscs()==null&&query.getDescs()==null){
//            query.setAscs("directorship_id");
//            query.setDescs("create_time");
//        }
//
//        List<SearchEntity> entityList = query.getSearch();
//        QueryWrapper<Director> queryWrapper = SearchParamEntiy.getQueryWrapper(
//                Condition.getQueryWrapper(new Director()), entityList
//        );
//        queryWrapper.eq("create_company_id", TokenUtil.getTokenOrgId());
//
//        IPage<Director> pages = directorService.page(Condition.getPage(query), queryWrapper);
//        List<DirectorVO> directorVOS = directorWrapper.entityToVO(pages.getRecords());
//        ListResult<DirectorVO> listResult = new ListResult<>(CommonCode.SUCCESS);
//        listResult.setList(directorVOS);
//        listResult.setTotal(Long.valueOf(pages.getTotal()).intValue());
//        return listResult;
//    }
//
//    /**
//     * 新增或修改 董事会
//     */
//    @PostMapping("/submit")
//    @Resubmit(delaySeconds = 0)
//    public R submit(@Valid @RequestBody Director director) {
//        if (director.getId() == null) {
//            director.setFormType(String.valueOf(FormTypeConstant.HR_DIRECTOR_FORM));
//        }
//        if (StringUtils.isNotBlank(director.getDocumentNumber())){
//            director.setDocumentNumber(EncryptUtil.encryptBase64(director.getDocumentNumber(), BASE64_KEY));
//        }
//        return directorService.saveOrUpdate(director) ? new R(CommonCode.SUCCESS) : new R(CommonCode.FAIL);
//    }
//
//
//    /**
//     * 删除 董事会
//     */
//    @PostMapping("/remove")
//    public R remove(@RequestBody PageData pd) {
//        List<String> ids = (List<String>)pd.get("ids");
//        return directorService.deleteLogic(Func.toLongList(StringUtils.join(ids, StringPool.COMMA)))
//                ? new R(CommonCode.SUCCESS) : new R(CommonCode.FAIL);
//    }
//
//    /**
//     *
//     * @param directorDTO
//     * @return
//     */
//    @PostMapping("/report")
//    public ObjResult reportTable(@RequestBody DirectorDTO directorDTO) {
//        ReportReturnVO reportReturnVO = directorService.report(directorDTO);
//        ObjResult objResult = new ObjResult(CommonCode.SUCCESS);
//        if (Optional.ofNullable(reportReturnVO).isPresent()){
//            PageData pd = new PageData();
//            pd.put("grids", reportReturnVO.getGrids());
//            objResult.setPageData(pd);
//        }
//        return objResult;
//
//    }
//
//    @GetMapping("/encryptBase64Data")
//    public void encryptBase64Data(){
//        List<Director> directors = directorService.list(Wrappers.<Director>lambdaQuery().isNotNull(Director::getDocumentNumber));
//        for (Director director : directors){
//            if (StringUtil.isNotBlank(director.getDocumentNumber())){
//                director.setDocumentNumber(EncryptUtil.encryptBase64(director.getDocumentNumber(), BASE64_KEY));
//            }
//        }
//        directorService.updateBatchById(directors);
//    }
//
//}
